#ifndef _ERP_GIS_CORE_AO_LIBER_H_
#define _ERP_GIS_CORE_AO_LIBER_H_

#include <map>


#include "c2cent/library/log/CWWLog2.h"
using namespace c2cent::library::wwlog;

namespace erp
{
namespace gis
{
namespace ao
{

class CLiber
{
	public:
		CLiber()
		{
			m_dwGuestNum=0;
			m_dwTimeNow=0;
		}
		~CLiber(){}
		uint32_t Checkin(const uint32_t dwProtocol,const uint32_t iRetCode)
		{
			if(iRetCode==0)
			{
				std::map<uint32_t,uint32_t>::iterator it = m_mapLiber.find(dwProtocol);
				if(it==m_mapLiber.end())
				{
					m_mapLiber[dwProtocol]=1;
				}
				else
				{
					m_mapLiber[dwProtocol]++;
				}
				m_dwGuestNum++;
			}
			return iRetCode;
		}
		uint32_t Checkout(const uint32_t dwProtocol, const int32_t iRetCode)
		{
			std::map<uint32_t,uint32_t>::iterator it = m_mapLiber.find(dwProtocol);
			if(it != m_mapLiber.end())
			{
				if(it->second>0)
				{
					it->second--;
					m_dwGuestNum--;
				}
			}
			return iRetCode;
		}
		void Reset()
		{
			m_dwTimeNow=time(0);
			m_mapLiber.clear();
			m_dwGuestNum=0;
		}
		void Clear()
		{
			m_mapLiber.clear();
			m_dwGuestNum=0;
		}
		bool Empty() const
		{
			return (m_dwGuestNum==0?true:false);
		}
		uint32_t GetTimeNow() const
		{
			return m_dwTimeNow;
		}
		const std::map<uint32_t,uint32_t>& GetLiber() const
		{
			return m_mapLiber;
		}
	private:
		std::map<uint32_t,uint32_t> m_mapLiber;
		uint32_t m_dwGuestNum;
		uint32_t m_dwTimeNow;
};

}
}
}

#endif /*_ERP_GIS_CORE_AO_LIBER_H_*/

